// pages/publish/buy/buy.js
import Https from "../../../utils/api.js"
const http = new Https
Page({

  /**
   * 页面的初始数据
   */
  data: {
		img:["../../../assets/publish/02.jpg"],
		name:"",
		phone:"",
		currentTypeChoose:0,
		currentFitmentChoose:0,
		currentSpecificationChoose:0,
		type:[
			"住宅",
			"别墅",
			"商铺",
			"写字楼",
		],
		fitment:[
			"简装",
			"精装",
			"豪装",
			"毛坯",
			"不限",
		],
		specification:[
			"一室",
			"二室",
			"三室",
			"四室",
			"五室",
			"五室以上"
		],
		area:'',
		houseType:'',
		fitments:"",
		few_room:"",
		community:"",
		budget:""

  },
	change(e){
		this.setData({
			area:e.detail.value
		})
	},
	publish(){
		let that=this;
		let reg = /^[\u4E00-\u9FA5]+$/;
		if (!reg.test(that.data.name)) {
			wx.showToast({
				title: '请输入正确的称呼',
				icon: "none"
			})
			return
		}
		let reg1 = /^1[3456789]\d{9}$/;
		if(!reg1.test(this.data.phone)){
			wx.showToast({
				title: '请输入正确手机号',
				icon: "none"
			})
			return
		};

		let data = {
			name:this.data.name,
			community:this.data.community,
			type:this.data.houseType,
			fitment:this.data.fitments,
			few_room:this.data.few_room,
			area:this.data.area,
			budget:this.data.budget,
			phone:this.data.phone,
			request_type:0,
			province:wx.getStorageSync('province')
		}

	http.request("home/asksfor",data,"POST").then((res)=>{
		console.log(res) 
		if(res.code == 200){
			wx.showModal({
				title:'发布成功',
				content:'全新找房模式即将开始，服务顾问将尽快与您联系',
				duration:"2000"
			})
			wx.navigateTo({
				url: '/pages/publish/publish.wxml',
			})
		}else{
			wx.showToast({
				title: res.data,
				icon:"error",
				duration:1500
			})
		}
		return
	})
		
		
	},
	type(e){
		this.setData({
			currentTypeChoose:e.currentTarget.dataset.index,
			houseType:e.currentTarget.dataset.item
		})	
	},
	fitment(e){
		this.setData({
			currentFitmentChoose:e.currentTarget.dataset.index,
			fitments:e.currentTarget.dataset.item
		})	
	},
	specification(e){
		this.setData({
			currentSpecificationChoose:e.currentTarget.dataset.index,
			few_room:e.currentTarget.dataset.item
		})	
	},
	name(e){
		this.setData({
			name:e.detail.value
		})
	},
	number1(e){
		this.setData({
			phone:e.detail.value
		})
	},

	community(e){
		this.setData({community:e.detail.value})
	},

	budget(e){
		this.setData({
			budget:e.detail.value
		})
	},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
		//判断是否登录
		let userInfo=wx.getStorageSync("userInfo");
		if(!userInfo){
			wx.showModal({
				title:"请先登录",
				content:"仅对注册用户开放。"
			})
			wx.switchTab({
				url: '/pages/my/my.js',
			})
			return
		}
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})